var winHeight;

var userName;
var password;

var uname;
var psw;

$(function(){
    userName = $(".bodyDiv>.login>.userName");
    password = $(".bodyDiv>.login>.psw");

    userName.bind("keypress",keyPressCheck);
    password.bind("keypress",keyPressCheck);

    onResize();

    $(window).resize(onResize);

    $(".btnLogin").bind("click",clickLogin);

    function keyPressCheck(event){
        if(event.keyCode==13){
            clickLogin();
        }
    }

    function onResize(){
        winHeight = Math.max($(window).height(),620);
        var loginTop = winHeight/2 - 155;
        var bgTop = loginTop - 190;
        $(".bodyDiv").css("background-position","center "+bgTop+"px");
        $(".login").css("margin-top",loginTop+"px");
    }

    function clickLogin(){
        var checked = true;
        checked = checkInfo();
        if(checked){
            loginForm.uname.value = uname;
            loginForm.pwd.value = psw;
            loginForm.action = $(".bodyDiv>.login>.btn-group>.btn-left").attr("link");
            loginForm.submit();
        }
    }

    function checkInfo(){
        var checked = true;
        uname = userName.val();
        psw = password.val();
        if(uname==""||uname==undefined||uname==null){
            checked = false;
            alert("Please enter your user name.");
            userName.focus();
        }else if(psw==""||psw==undefined||psw==null){
            checked=false;
            alert("Please enter your password.");
            password.focus();
        }
        return checked;
    }
});